﻿Imports System.Web
Imports System.Web.Services
Imports MeoTom.Core.BLL
Imports MeoTom.Core

Public Class Votes
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim util As New Utilities.Common()
        Dim v As New Global.MeoTom.Core.BLL.Votes()
        context.Response.ContentType = "text/plain"
        Try
            Dim TongSoLuot As String = context.Request.QueryString("tongsoluot").ToString()
            Dim SoDiemBinhChonMoi As String = context.Request.QueryString("sodiembinhchonmoi").ToString()
            Dim ArticleID As String = context.Request.QueryString("sId").ToString()
            If IsNumeric(TongSoLuot) Then
                If IsNumeric(SoDiemBinhChonMoi) Then
                    If Not util.GetCookie("ArticleVote_" & ArticleID) = "true" Then
                        v.ArticleID = context.Request.QueryString("sId").ToString()
                        v.TotalRating = Integer.Parse(TongSoLuot)
                        v.Votes = Decimal.Parse(SoDiemBinhChonMoi)
                        v.UpVote()
                        util.SetCookie("ArticleVote_" & ArticleID, "true")
                        context.Response.Write("OK")
                    Else
                        context.Response.Write("Voted")
                    End If
                Else
                    context.Response.Write("Fail")
                End If
            Else
                context.Response.Write("Fail")
            End If
        Catch ex As Exception
            context.Response.Write("Fail")
        End Try
    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class